const config = require("../config/config");
const { PhotoService } = require("../services/photo_service");

const checkAndMake = async (url, id, data) => {
  return Promise.all([
    new Promise((resolve, reject) => {
      let photoService = new PhotoService();
      photoService.imageRisk(url).then(res => {
        resolve({
          action: res.data.resultAction
        })
      })
    }),

    new Promise((resolve, reject) => {
      wx.request({
        url: "https://api.zheyings.cn/idcardv5/make",
        method: "POST",
        header: {
          "content-type": "application/x-www-form-urlencoded" // 默认值
        },
        data: {
          key: config.apiKey,
          item_id: id,
          image: data,
          beauty: 0
        },
        success: res => {
          resolve(res.data);
        }
      });
  
    })
  ]);
}

module.exports = checkAndMake;